/**
 * Copyright (c) 2015-2017, Henry Yang 杨勇 (gismail@foxmail.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mapfinal.server.auth;

import java.util.List;

import com.jfinal.kit.Ret;
import com.lambkit.common.service.LambkitService;
import com.mapfinal.server.auth.model.AuthOrganization;
import com.mapfinal.server.auth.model.Role;
import com.mapfinal.server.auth.model.User;

/**
 * @author yangyong 
 * @website: www.lambkit.com
 * @email: gismail@foxmail.com
 * @date 2020-09-23
 * @version 1.0
 * @since 1.0
 */
public interface UserService extends LambkitService<User> {
	public User getUser(String name, String pass);
	
	public User findByUuid(String uuid);
	
	public User findByUserName(String name);
	
	public User findByUserNameCache(String name);
	
	public User findByEmail(String name);
	
	public User findByPhone(String name);
	
	public User findByLoginName(String name);
	
	public String getPasswordSecurity(String pass);
	/**
	 * 加密
	 * @param password
	 * @return
	 */
	public String getPasswordMD5(String password);
	
	/**
	 * 用户名是否已被注册
	 */
	public boolean isUserNameExists(String userName);
	
	/**
	 * 昵称是否已被注册，昵称不区分大小写，以免存在多个用户昵称看起来一个样的情况
	 *
	 *  mysql 的 where 字句与 order by 子句默认不区分大小写，区分大小写需要在
	 *  字段名或字段值前面使用 binary 关键字例如：
	 *  where nickName = binary "jfinal" 或者 where binary nickName = "jfinal"，前者性能要高
	 *
	 *  为了避免不同的 mysql 配置破坏掉 mysql 的 where 不区分大小写的行为，这里在 sql 中使用
	 *  lower(...) 来处理，参数 nickName 也用 toLowerCase() 方法来处理，再次确保不区分大小写
	 */
	public boolean isNickNameExists(String nickName);
	
	/**
	 * 添加角色
	 */
	public Ret addRole(int accountId, int roleId);

	/**
	 * 删除角色
	 */
	public Ret deleteRole(int accountId, int roleId);
	
	/**
	 * 标记出 account 拥有的角色
	 * 未来用 role left join account_role 来优化
	 */
	public void markAssignedRoles(User account, List<Role> roleList);

	/**
	 * 标记出 account 拥有的公司
	 * @param account
	 * @param roleList
	 */
	public void markAssignedOrganizations(User account, List<AuthOrganization> orgList);

	/**
	 * 添加公司
	 * @param paraToInt
	 * @param paraToInt2
	 * @param paraToInt3
	 * @param para
	 * @return
	 */
	public Ret setOrganization(Long accountId, Integer orgId, Integer jobId, String jobs);

	/**
	 * 删除公司
	 * @param paraToInt
	 * @param paraToInt2
	 * @return
	 */
	public Ret deleteOrganization(Long accountId, Integer orgId);
	
	
}
